package GUI;


import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.GridLayout;

import logic.Message;
import javax.swing.UIManager;

public class Member_menu extends JPanel {
	
	private Client_GUI parent;
	
	private JButton btnPersonalInfo;
	private JButton btnActivityInfo;
	
	private boolean info = false;
	
	public Member_menu(final Client_GUI parent) {
		this.setBackground(Color.WHITE);

		this.parent = parent;
		this.setSize(parent.MENU_WIDTH, parent.MENU_HEIGHT);
		setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBackground(UIManager.getColor("inactiveCaptionBorder"));
		panel.setBounds(0, 0, 150, 330);
		add(panel);
		panel.setLayout(new GridLayout(0, 1, 0, 0));
		
		JButton btnHome = new JButton("Home");
		panel.add(btnHome);
		btnHome.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				Home home = new Home(parent,parent.client.publicMessages);
				parent.RepaintMain(home);
			}
		});
		
		JButton btnSearchBook = new JButton("Search Book");
		btnSearchBook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SearchBook topaint = new SearchBook(parent,Message.SEARCH_BOOK_REQUEST,null);
				parent.RepaintMain(topaint);
			}
		});
		panel.add(btnSearchBook);
		
		JButton btnViewOpenOrders = new JButton("View Orders");
		btnViewOpenOrders.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				SearchOrder topaint = new SearchOrder(parent);
				//parent.RepaintMain(topaint);
				
			}
		});
		panel.add(btnViewOpenOrders);
		
		JButton btnViewOpenLoans = new JButton("View Loans");
		btnViewOpenLoans.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				SearchLoan topaint = new SearchLoan(parent,SearchLoan.SEARCH_LOAN,null);
				//parent.RepaintMain(topaint);
			}
		});
		panel.add(btnViewOpenLoans);
		
		JButton btnOrderABook = new JButton("Order A Book");
		btnOrderABook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Book_opp bookOperations = new Book_opp(parent,Message.CREATE_ORDER_REQUEST,Integer.parseInt(parent.client.GetUID()));
				parent.RepaintMain(bookOperations);
			}
		});
		panel.add(btnOrderABook);
		
		JButton btnViewInfo = new JButton("View Info");
		btnViewInfo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				SetStockVisibility(!info);
			}
		});
		panel.add(btnViewInfo);
		
		btnPersonalInfo = new JButton("Personal Info");
		btnPersonalInfo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SearchMember topaint = new SearchMember(parent, SearchMember.SEARCH, null);
			}
		});
		panel.add(btnPersonalInfo);
		
		btnActivityInfo = new JButton("Activity Info");
		panel.add(btnActivityInfo);
		

		

		
		btnPersonalInfo.setVisible(false);
		btnActivityInfo.setVisible(false);
	}
	
	/**
	 * Set the Stock Info button group's visiblity
	 * @param value - visibilty value to set
	 */
	private void SetStockVisibility(boolean value){
		btnPersonalInfo.setVisible(value);
		btnActivityInfo.setVisible(value);
		
		info = value;
	}

}
